package com.voxel.sense.infomsg.net.helper;

import com.example.com.common.factory.data.DataSource;

import java.util.List;

import cyy.example.com.facotry.constants.Constants;
import cyy.example.com.facotry.model.api.BaseEntity;
import cyy.example.com.facotry.model.api.request.SendTaskEntity;
import cyy.example.com.facotry.model.api.response.MyTaskListInfoEntity;
import cyy.example.com.facotry.model.api.response.StreetAndFirmEntity;
import cyy.example.com.facotry.model.api.response.TaskActionGroupEntity;
import cyy.example.com.facotry.model.api.response.TaskFileEntity;
import cyy.example.com.facotry.model.api.response.TaskStatuEntity;
import cyy.example.com.facotry.net.Network;
import cyy.example.com.facotry.net.RemoteService;
import cyy.example.com.facotry.net.RequestIdFactory;
import cyy.example.com.facotry.net.helper.RspCallback;
import cyy.example.com.facotry.share.SPEngine;
import retrofit2.Call;

/**
 * 任务管理模块的相关请求类
 * Created by ChenYiYao on 2017/12/14.
 */

public class TaskManagerNetHelper {

    /**
     * @param pageNum    页数
     * @param taskStatus 0：未接收 1:执行中 2：执行完成  不传或-1:查询个人所有相关任务
     * @return
     */
    public static Call queryMyTaskInfoList(int pageNum, String taskStatus, String sortType, List<String> areaName, List<String> industryId, DataSource.Callback callback) {
        return queryMyTaskInfoList(Constants.TASK_LIST_PAGE_DATA_SIZE, pageNum, taskStatus, sortType, areaName, industryId, callback);
    }

    /**
     * 获取与我相关的任务列表
     *
     * @param pageNum    页数
     * @param pageSize   每页的个数
     * @param taskStatus 0：未接收 1:执行中 2：执行完成  不传或-1:查询个人所有相关任务
     * @return
     */
    public static Call queryMyTaskInfoList(int pageSize, int pageNum, String taskStatus, String sortType, List<String> areaName, List<String> industryId, DataSource.Callback callback) {
        RemoteService remote = Network.remote();
        String user_id = SPEngine.getSPEngine().getUserInfo().getUser_id();

//        List<String> areaName,
//        @Query("taskType") List<String> industryId

        Call<MyTaskListInfoEntity> call = remote.getTaskInfo(user_id, taskStatus, pageSize, pageNum, sortType, areaName, industryId);
        call.enqueue(new RspCallback<MyTaskListInfoEntity>(callback, RequestIdFactory.GET_TASK_INFO_LIST));
        return call;
    }


    /**
     * 获取执行任务的分组类型
     *
     * @param callback
     * @return
     */
    public static Call getUserTaskGroup(DataSource.Callback callback) {
        RemoteService remote = Network.remote();
        Call<TaskActionGroupEntity> call = remote.getTakeTaskGroup();
        call.enqueue(new RspCallback<TaskActionGroupEntity>(callback, RequestIdFactory.GET_USER_TASK_GROUP));
        return call;
    }

    /**
     * 获取街道和公司
     *
     * @param callback
     * @return
     */
    public static Call getAreaFirm(String cityName, String areaName, DataSource.Callback callback) {
        RemoteService remote = Network.remote();
        Call<StreetAndFirmEntity> call = remote.getStreentAndFirm();
        call.enqueue(new RspCallback<StreetAndFirmEntity>(callback, RequestIdFactory.QUERY_AREA_FIRM));
        return call;
    }

    /**
     * 派发任务
     *
     * @param workName      任务名称
     * @param workType      任务类型
     * @param workAddress   任务地点
     * @param workContent   任务内容
     * @param workStartTime 任务开始时间
     * @param workEndTime   任务结束时间
     * @param workObject    任务对象
     * @param workEmp       任务执行人员
     * @return
     */
    public static Call sendTask(String workName, String workType, String workAddress, String workContent,
                                long workStartTime, long workEndTime, List<String> workObject, List<String> workEmp, DataSource.Callback callback) {
        RemoteService remote = Network.remote();
        SendTaskEntity entity = new SendTaskEntity();
//        entity.setWorkName(workName);
//        entity.setWorkType(workType);
//        entity.setWorkAddress(workAddress);
//        entity.setWorkContent(workContent);
//        entity.setWorkStartTime(workStartTime);
//        entity.setWorkEndTime(workEndTime);
//        entity.setWorkObject(workObject);
//        entity.setWorkEmp(workEmp);
//
//        String user_id = SPEngine.getSPEngine().getUserInfo().getUser_id();
//        entity.setWorkSender(user_id);
        Call<BaseEntity> call = remote.SendTask(entity);
        call.enqueue(new RspCallback<BaseEntity>(callback, RequestIdFactory.SEND_TASK));
        return call;
    }

    /**
     * 接收任务
     *
     * @param callback
     * @return
     */
    public static Call acceptTask(String taskNumber, DataSource.Callback callback) {
        RemoteService remote = Network.remote();
        String user_id = SPEngine.getSPEngine().getUserInfo().getUser_id();
        Call<TaskStatuEntity> call = remote.receiveTask(user_id, taskNumber);
        call.enqueue(new RspCallback<TaskStatuEntity>(callback, RequestIdFactory.ACCEPT_TASK));
        return call;
    }

    /**
     * 执行任务
     *
     * @param callback
     * @return
     */
    public static Call executeTask(String taskNumber, DataSource.Callback callback) {
        RemoteService remote = Network.remote();
        String user_id = SPEngine.getSPEngine().getUserInfo().getUser_id();
        Call<TaskStatuEntity> call = remote.executeTask(user_id, taskNumber);
        call.enqueue(new RspCallback<TaskStatuEntity>(callback, RequestIdFactory.EXECUTE_TASK));
        return call;
    }

    /**
     * 获取已执行的任务所上传的文件资料
     *
     * @param callback
     * @return
     */
    public static Call getTaskFile(String taskNumber, DataSource.Callback callback) {
        RemoteService remote = Network.remote();
        Call<TaskFileEntity> call = remote.getCheckTakeFile(taskNumber);
        call.enqueue(new RspCallback<TaskFileEntity>(callback, RequestIdFactory.GET_TASK_FILE));
        return call;
    }

    /**
     *
     * @param taskNumber 任务编号
     * @param opinionMsg 意见
     * @param isPass    1：通过  0：不通过
     * @return
     */
    public static Call checkTask(String taskNumber, String opinionMsg, String isPass, DataSource.Callback callback) {
        RemoteService remote = Network.remote();
        String user_id = SPEngine.getSPEngine().getUserInfo().getUser_id();
        Call<BaseEntity> call = remote.CheckTask(user_id, taskNumber, opinionMsg, isPass);
        call.enqueue(new RspCallback<BaseEntity>(callback, RequestIdFactory.CHECK_TASK));
        return call;
    }
}
